/*
 *  Parabora.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/07/01.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "Parabola.h"
#include "Line.h"
#include <cmath>

namespace sc
{
	Parabola::Parabola()
		: Line( Type_Parabola, 0, 0, 0, 0 )
	{}

	Parabola::Parabola( Type type, double startX, double startY, double endX, double endY )
		: Line( type, startX, startY, endX, endY )
	{}

	Parabola::~Parabola()
	{}

	bool Parabola::operator < ( const Parabola& rhs ) const
	{
		bool isEqaul;

		isEqaul = coefficientA == rhs.coefficientA;
		if ( ! isEqaul )
		{
			return coefficientA < rhs.coefficientA;
		}
	
		isEqaul = coefficientB == rhs.coefficientB;
		if ( ! isEqaul )
		{
			return coefficientB < rhs.coefficientB;
		}

		isEqaul = coefficientC == rhs.coefficientC;
		if ( ! isEqaul )
		{
			return coefficientC < rhs.coefficientC;
		}
		return false;
	}

	bool Parabola::operator > ( const Parabola& rhs ) const
	{
		bool isEqaul;

		isEqaul = coefficientA == rhs.coefficientA;
		if ( ! isEqaul )
		{
			return coefficientA > rhs.coefficientA;
		}
	
		isEqaul = coefficientB == rhs.coefficientB;
		if ( ! isEqaul )
		{
			return coefficientB > rhs.coefficientB;
		}

		isEqaul = coefficientC == rhs.coefficientC;
		if ( ! isEqaul )
		{
			return coefficientC > rhs.coefficientC;
		}
		return false;

	}
		
	bool Parabola::operator <= ( const Parabola& rhs ) const
	{
		return ! ( *this > rhs );
	}

	bool Parabola::operator >= ( const Parabola& rhs ) const
	{
		return ! ( *this < rhs );
	}
	
	double Parabola::GetY( double paramX ) const
	{
		return coefficientA * std::pow ( ( paramX - coefficientB ), 2.0 ) + coefficientC;
	}
	
	std::string Parabola::ToString() const
	{
		std::stringstream ss;
		ss << Line::ToString() << "\n\t"
			<< "coefficientA: " << coefficientA << ", coefficientB: " << coefficientB << ", coefficientC: " << coefficientC; 
		return ss.str();
	}

}
